async function fn1() {
  // return 100  //相当于 return Promise.resolve(100)
  return Promise.resolve(200)
}

const res1 = fn1() //执行async函数，返回的是一个promise对象
console.log('res',res1);//promise 

res1.then((data) => {
  console.log('data',data);//200
})

!(async function() {
  const p1 = Promise.resolve(300)
  const data = await p1 // await 相当于 promise.then
  console.log('data',data);
})()

!(async function() {
  const data = await 400 // 相当于 await promise.resolve(400)
  console.log('data',data);
})()


!(async function() {
  const p4 = Promise.reject('err1')
  try {
    const res = await p4 // try catch 相当于 promise catch
  } catch (ex) {
    console.log(ex);
  }
})()

!(async function() {
  const p5 = Promise.reject('err1') //await => promise.then()    rejected 不执行，用try catch
  const res = await p5
  console.log(res);
})()


// async await 是消灭异步回调的终极武器
// js还是单线程，还得有异步，还得基于 event loop
// async await是语法糖
